package com.ebelter.bodyfatscale.util;


import android.content.Context;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import java.util.Locale;

public class AppUtils {

    private static final String TAG = "AppUtils";

    /**
     * 获取当前本地apk的版本
     */
    public static int getVersionCode(Context mContext) {
        int versionCode = 0;
        try {
            //获取软件版本号，对应AndroidManifest.xml下android:versionCode
            versionCode = mContext.getPackageManager().
                    getPackageInfo(mContext.getPackageName(), 0).versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionCode;
    }

    /**
     * 获取版本号名称
     */
    public static String getVerName(Context context) {
        String verName = "";
        try {
            verName = context.getPackageManager().
                    getPackageInfo(context.getPackageName(), 0).versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return verName;
    }



    public static final  String zh="zh";//中文
    public static final  String en="en"; //英文
    public static final  String ko="ko"; //韩语
    public static final  String fr="fr"; //法语
    public static final  String de="de"; //德语
    public static final  String ja="ja"; //日语
    public static final  String ru="ru"; //俄语
    public static final  String iw="iw"; //希伯来语
    public static final  String il="il"; //爱尔兰
    public static String getLocalStr(){
//        获取系统语言 方法：Locale.getDefault().getLanguage()
//        获取应用语言 方法：getResources().getConfiguration().locale.getLanguage()

        String systemLanguage = Locale.getDefault().getLanguage();
     //   String appLanguage = ApplicationHelper.mApplicationContecx.getResources().getConfiguration().locale.getLanguage();
       // ULog.i(TAG,"---systemLanguage="+systemLanguage+"----appLanguage="+systemLanguage);
        if (TextUtils.isEmpty(systemLanguage)){
            return zh;
        }
        systemLanguage=systemLanguage.toLowerCase();
        if (systemLanguage.contains(zh)){
            return zh;
        }else if (systemLanguage.contains(ko)){
            return ko;
        }else if (systemLanguage.contains(fr)){
            return fr;
        }else if (systemLanguage.contains(de)){
            return de;
        }else if (systemLanguage.contains(ja)){
            return ja;
        }else if (systemLanguage.contains(ru)){
            return ru;
        }else if(systemLanguage.contains(iw)||systemLanguage.contains(il)){//有的手机
            return iw;
        }else {
            return en;
        }

    }

}
